import ACCESS_ENUM from "@/access/accessEnum";
import AccessEnum from "@/access/accessEnum";

const checkAccess = (
  loginUser: API.UserVO,
  needAccess = ACCESS_ENUM.NOT_LOGIN,
) => {
  const loginUserAccess = loginUser?.userRole ?? AccessEnum.NOT_LOGIN;
  // 不需要登录权限
  if (needAccess === ACCESS_ENUM.NOT_LOGIN) {
    return true;
  }
  // 需要登录权限
  if (needAccess === ACCESS_ENUM.USER) {
    // 判断是否登录
    if (loginUserAccess === ACCESS_ENUM.NOT_LOGIN) {
      return false;
    }
  }
  // 需要管理员权限
  if (needAccess === ACCESS_ENUM.ADMIN) {
    if (loginUserAccess !== ACCESS_ENUM.ADMIN) {
      return false;
    }
  }
  return true;
};

export default checkAccess;